package br.com.cicero.notasfiscais.conversores;

import javax.faces.component.UIComponent;
import javax.faces.context.FacesContext;
import javax.faces.convert.Converter;
import javax.faces.convert.FacesConverter;

import br.com.caelum.stella.format.CNPJFormatter;

@FacesConverter("cnpj")
public class ConversorCNPJ implements Converter {

	@Override
	public Object getAsObject(FacesContext context, UIComponent component, String valor) {
		return new CNPJFormatter().unformat(valor);
	}

	@Override
	public String getAsString(FacesContext context, UIComponent component, Object valor) {
		return new CNPJFormatter().format(valor.toString());
	}

}
